package com.zaixiandiancan.xia.util;


import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class SessionInterceptor implements HandlerInterceptor {

    public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
            throws Exception {
    }
    public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
            throws Exception {
    }
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
        //普通路径放行
        if ("/login".equals(request.getRequestURI())) {
            return true;}
        //权限路径拦截
        Object object = request.getSession().getAttribute("users");
        if (null == object) {
            response.sendRedirect("/user/login_index");
            return false;}
        return true;
    }
}  